package com.example.content.fragment.me.vip

import android.view.LayoutInflater
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.content.R
import com.example.content.adapter.recycle.BindListener
import com.example.content.adapter.recycle.RecyclerAdapter
import com.example.content.adapter.recycle.entity.ItemEntity
import com.example.content.databinding.VipCenterLayoutBinding
import com.example.content.fragment.BaseMvvmFragment
import com.example.content.viewmodule.me.MyPageCommonViewModel
import com.gyf.immersionbar.ImmersionBar

/**
 * Created by zhudongao
 * Desc
 * Date 2020/11/8
 */
class MyVipFragment : BaseMvvmFragment<VipCenterLayoutBinding, MyPageCommonViewModel>()  {

    private lateinit var privacyAdapter:RecyclerAdapter<PrivacyData>
    private lateinit var viewPagerAdapter:VipCardPagerAdapter

    override fun initView() {
        ImmersionBar.with(this).statusBarColor(R.color.normal_black_text).statusBarDarkFont(false).init()

        val list = mutableListOf<View>()
        for (i in 0..6) {
            val view = LayoutInflater.from(context).inflate(R.layout.vip_center_card_layout, null)
            list.add(view)
        }
        viewPagerAdapter = VipCardPagerAdapter(list)
        dataBinding.cardViewPager.adapter = viewPagerAdapter
        dataBinding.cardViewPager.offscreenPageLimit = 3
        dataBinding.cardViewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener{
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {

            }

            override fun onPageSelected(position: Int) {
                vipLevel(position)
            }

            override fun onPageScrollStateChanged(state: Int) {

            }

        })

        privacyAdapter = RecyclerAdapter(object : BindListener<PrivacyData>{
            override fun convert(holder: BaseViewHolder, item: ItemEntity<PrivacyData>) {

            }
        })
        for (i in 0..6) {
            privacyAdapter.addData(ItemEntity(data = PrivacyData(0, "", "")))
        }

        privacyAdapter.addItemView(R.layout.vip_privacy_item_layout)
        dataBinding.recyclerPrivilege.adapter = privacyAdapter
        dataBinding.recyclerPrivilege.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
    }

    private fun vipLevel(position: Int) {
        val vipLevel = when (position) {
            0 -> {
                R.drawable.vip_degree_v1
            }
            1 -> {
                R.drawable.vip_degree_v2
            }
            2 -> {
                R.drawable.vip_degree_v3
            }
            3 -> {
                R.drawable.vip_degree_v4
            }
            4 -> {
                R.drawable.vip_degree_v5
            }
            5 -> {
                R.drawable.vip_degree_v6
            }
            6 -> {
                R.drawable.vip_degree_v7
            }
            else -> {
                R.drawable.vip_degree_v1
            }
        }
        dataBinding.vipDegreeVipIcon.setImageResource(vipLevel)
    }

    override fun getLayoutId() = R.layout.vip_center_layout

    companion object {
        fun newInstance() = MyVipFragment()
    }

    override fun getViewModuleClass(): Class<MyPageCommonViewModel> {
        return MyPageCommonViewModel::class.java
    }
}